package com.joyintech.modules.pmp.rest;

import com.joyintech.annotation.Log;
import com.joyintech.modules.pmp.service.DsAppService;
import com.joyintech.modules.pmp.service.dto.DsAppDto;
import com.joyintech.modules.pmp.service.dto.DsAppQueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
* @author daiweiwei
* @date 2021-09-27
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "DsApp管理")
@RequestMapping("/api/dsApp")
public class DsAppController {

    private final DsAppService dsAppService;

    @GetMapping
    @Log("查询DsApp")
    @ApiOperation("查询DsApp")
    @PreAuthorize("@el.check('dsApp:list')")
    public ResponseEntity query(DsAppQueryParam query, Pageable pageable){
        return new ResponseEntity<>(dsAppService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增DsApp")
    @ApiOperation("新增DsApp")
    @PreAuthorize("@el.check('dsApp:add')")
    public ResponseEntity create(@Validated @RequestBody DsAppDto resources){
        return new ResponseEntity<>(dsAppService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改DsApp")
    @ApiOperation("修改DsApp")
    @PreAuthorize("@el.check('dsApp:edit')")
    public ResponseEntity update(@Validated @RequestBody DsAppDto resources){
        dsAppService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除DsApp")
    @ApiOperation("删除DsApp")
    @PreAuthorize("@el.check('dsApp:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        dsAppService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出DsApp")
    @ApiOperation("导出DsApp")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('dsApp:list')")
    public void download(HttpServletResponse response, DsAppQueryParam query) throws IOException {
        dsAppService.download(dsAppService.queryAll(query), response);
    }*/

}
